<?php
class Audio {
	const SEL_TOP_10 = "SELECT id, titulo FROM audios WHERE status = 'A' ORDER BY fecha_publicacion DESC, id DESC LIMIT 10";
	const SEL_TOP_20 = "SELECT * FROM audios WHERE status = 'A' ORDER BY fecha_publicacion DESC, id DESC LIMIT 20";

	public function getTop10() {
		$SQL = self::SEL_TOP_10;

		$q = mysql_query($SQL) or die(mysql_error());

		$arrAudio = array();
		$i = 0;

		while ($row = mysql_fetch_array($q)) {
			$arrAudio[$i]['id'] = $row['id'];
			$arrAudio[$i]['titulo'] = $row['titulo'];
			$i++;
		}

		return $arrAudio;
	}

	public function getTop20() {
		$SQL = self::SEL_TOP_20;

		$q = mysql_query($SQL) or die(mysql_error());

		$arrAudio = array();
		$i = 0;

		while ($row = mysql_fetch_array($q)) {
			$arrAudio[$i]['id'] = $row['id'];
			$arrAudio[$i]['titulo'] = $row['titulo'];
			$arrAudio[$i]['link_text'] = $row['link_text'];
			$arrAudio[$i]['fecha_publicacion'] = $row['fecha_publicacion'];
			$i++;
		}

		return $arrAudio;
	}

	public function insertAudio($link_text, $fecha_publicacion, $titulo) {
		$SQL = "INSERT INTO audios (link_text, fecha_publicacion, status, titulo) "
			."VALUES ('".$link_text."', '".$fecha_publicacion."', 'A', '".$titulo."')";

		$q = mysql_query($SQL) or die(mysql_error());
	}

	public function delAudio($id) {
		$SQL = "UPDATE audios SET status='S' WHERE id = ".$id;

		$q = mysql_query($SQL) or die(mysql_error());
	}
}